{{!
  Copyright (c) HashiCorp, Inc.
  SPDX-License-Identifier: BUSL-1.1
}}

<div class="box is-sideless is-fullwidth is-marginless" data-test-role-settings-section>
  <h3 class="title is-5">Role settings</h3>
  {{#if this.settingFields}}
    <div class="form-section">
      {{#each this.settingFields as |attr|}}
        {{#if (and (eq @mode "edit") (includes attr.name (array "skip_import_rotation" "username")))}}
          {{#if (eq attr.name "skip_import_rotation")}}
            <ReadonlyFormField @attr={{attr}} @value={{not (get @model attr.name)}} />
          {{else}}
            <ReadonlyFormField @attr={{attr}} @value={{get @model attr.name}} />
          {{/if}}
        {{else if (and (eq @mode "edit") (eq attr.name "password"))}}
          <EnableInput
            data-test-enable-field={{attr.name}}
            class="field"
            @attr={{attr}}
            {{! password field is disabled on edit once password has been rotated }}
            @disabled={{(not (eq (get @model "last_vault_rotation") undefined))}}
          >
            <FormField @attr={{attr}} @model={{@model}} />
          </EnableInput>
        {{else}}
          <FormField data-test-field={{true}} @attr={{attr}} @model={{@model}} @modelValidations={{@modelValidations}} />
          {{#if (and (eq attr.name "skip_import_rotation") this.isOverridden)}}
            <Hds::Alert @type="inline" @color="warning" class="has-top-margin-negative-s" as |A|>
              <A.Title>Warning</A.Title>
              <A.Description>This will override the connection default for this role.</A.Description>
            </Hds::Alert>
          {{/if}}
        {{/if}}

      {{/each}}
    </div>
  {{else}}
    <EmptyState @title="No role type selected" @message="Select a type of role to be able to configure it" />
  {{/if}}
</div>
{{! template-lint-configure simple-unless "warn"  }}
{{#unless (and @roleType (not this.statementFields))}}
  <div class="box is-sideless is-fullwidth is-marginless" data-test-statements-section>
    <h3 class="title is-5">Statements</h3>
    {{#if this.statementFields}}
      <div class="form-section">
        {{#each this.statementFields as |attr|}}
          <FormField data-test-field={{true}} @attr={{attr}} @model={{@model}} />
        {{/each}}
      </div>
    {{else}}
      <EmptyState
        @title="No role type selected"
        @message="Select a type of role to be able to add statements for creation, revocation, and/or rotation."
      />
    {{/if}}
  </div>
{{/unless}}